<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
        <style>
            .box {
                width: 50px;
                height: 50px;
                background-color: rgba(212, 254, 0, 1.5);
                border-radius: 50%;
                position: absolute;
            }
        </style>
    </head>
    <body>
        <div class="box"></div>
        <script>
            //获取元素
            let box = document.querySelector(".box");
            document.onmousemove = (event) => {
                let mouseY = event.pageY;//获取鼠标的据X轴线距离
                let mouseX = event.pageX;//获取鼠标的据y轴线距离
                //获取box的宽高
                let boxHight = box.offsetHeight;
                let boxWidth = box.offsetWidth;
                //改变他的属性
                //保持在中间
                //⚠️公式(mouseY - boxHight / 2)
                box.style.top = mouseY - boxHight / 2 + "px";
                box.style.left = mouseX - boxWidth / 2 + "px";
            };
        </script>
    </body>
</html>
